package br.edu.unilasalle.simon_test.cadastro;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import br.edu.unilasalle.simon_test.AbstractPage;

public class UsuarioPage extends AbstractPage {

	@FindBy(id = "btnAdicionar")
	protected WebElement adicionar;
	
	@FindBy(id = "selFunc")
	protected WebElement funcionario;
	
	@FindBy(id = "inputLogin")
	protected WebElement login;
	
	@FindBy(id = "inputSenha")
	protected WebElement senha;
	
	@FindBy(id = "selNivel")
	protected WebElement nivel;
	
	@FindBy(id = "btnAtualizar")
	protected WebElement atualizar;
	
	@FindBy(id = "btnIncluir")
	protected WebElement incluir;
	
	public UsuarioPage(WebDriver driver) {
		super(driver);
	}
	
	public void abreTela() {
		openAsAdmin();
		open("/#/usuarios-list");
	}
	
	public void cadastrarUsuario() throws Exception {
		adicionar.click();
		
		selectComboByValue(funcionario, "0");
		type(login, "usuTeste");
		type(senha, "1234");
		selectComboByValue(nivel, "1");
		
		find(incluir).click();
		waitAjaxComplete();
	}

	public void editarUsuario() {
		detalharRegistro("usuTeste");
		login.clear();
		type(login, "usuTeste2");
		atualizar.click();
		waitAjaxComplete();
	}

}
